/* GameBoardTile.java */

package gameboard;

import player.MachinePlayer.ChipType;

public class GameBoardTile {

	private ChipType chip;
	private boolean blackIsValid = true, whiteIsValid = true;
	private final int x, y;
	
	/**
	 * Constructs a new GameBoardTile. (GameBoard is the only class who should be making new 
	 * GameBoardTiles).
	 * @param x is the x location of this GameBoardTile
	 * @param y is the y location of this GameBoardTile
	 * @param b indicates whether this GameBoardTile is actually part of the 8 x 8 gameboard, if
	 * not, it is an invalid, empty GameBoardTile used as a filler.
	 */
	public GameBoardTile(int x, int y, boolean b) {
		chip = ChipType.EMPTY;
		this.x = x;
		this.y = y;
		if (!b) {
			changeValidity(ChipType.BLACK);
			changeValidity(ChipType.WHITE);
		}
	}
	
	/**
	 * This method returns the x-coordinate of the GBT.
	 * @return the x-coordinate
	 */
	public int getX() {
		return x;
	}
	
	/**
	 * This method returns the y-coordinate of the GBT.
	 * @return the y
	 */ 
	public int getY() {
		return y;
	}

	/**
	 * This method inserts a chip into the GameBoardTile.
	 * @param c is the type of Chip: black, white, or empty.
	 */
	protected void insert(ChipType c) {
		chip = c;
		if (c == ChipType.EMPTY) {
			blackIsValid = true;
			whiteIsValid = true;
		} else {
			whiteIsValid = false;
			blackIsValid = false;
		}
	}
	
	/**
	 * This method gets the current chip in this GameBoardTile.
	 * @return the current chip
	 */
	public ChipType getChip() {
		return chip;
	}
	
//	/**
//	 * This method changes the validity of the GameBoardTile for a black chip.
//	 * 
//	 */
//	protected void changeBlackValidity(){
//		blackIsValid = !blackIsValid;
//	}
//	
//	/**
//	 * This method changes the validity of the GameBoardTile for a white chip.
//	 */
//	protected void changeWhiteValidity(){
//		whiteIsValid = !whiteIsValid;
//	}
//	
//	/**
//	 * This method gets the validity for black of the GameBoardTile
//	 * @return the validity
//	 */
//	public boolean blackValidity(){
//		//System.out.println("blackIsValid is " + blackIsValid);
//		return blackIsValid;
//	}
//	
//	/**
//	 * This method gets the validity for white of the GameBoardTile
//	 * @return the validity
//	 */
//	public boolean whiteValidity(){
//		return whiteIsValid;
//	}

	/**
	 * This method changes the validity of the GameBoardTile for the given chip.
	 * @param c is the chipType.
	 */
	public void changeValidity(ChipType c) {
		if (c == ChipType.BLACK) {
			blackIsValid = !blackIsValid;
		} else if (c == ChipType.WHITE) {
			whiteIsValid = !whiteIsValid;
		}
	}
	
	/**
	 * This method gets the validity for the given chip type for this GBT.
	 * @param c is the chipType. 
	 * @return the validity
	 */
	public boolean getValidity(ChipType c) {
		// System.out.println("blackIsValid is " + blackIsValid);
		if (c == ChipType.BLACK) {
			return blackIsValid;
		} else if (c == ChipType.WHITE) {
			return whiteIsValid;
		} else {
			return true;
		}
	}
	

}
